package pickGifts;

import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Solution {
    public long pickGifts(int[] gifts, int k) {
        PriorityQueue<Integer> dq = new PriorityQueue<>((o1, o2) -> o2 - o1);
        for (int i = 0; i < gifts.length; i++) {
            dq.add(gifts[i]);
        }
        while (k>0) {
            dq.add((int)Math.sqrt(dq.poll()));
            k--;
        }
        long ans = 0;
        for (int num: dq) {
            ans+= num;
        }
        return ans;
    }
}
